﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ClassLibrary.DAO;
using ClassLibrary.Entity;
using ClassLibrary.Data;
using System.Collections.Generic;

public partial class ucControl_ucChiTietSP : System.Web.UI.UserControl
{
    ItemsDAO itemDAO = new ItemsDAO(Global.CONNECTION_STRING);

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            string id = Request.QueryString["id"];
            string idGroup = Request.QueryString["idgroup"];

            if (id != null || id != string.Empty & idGroup !=null || idGroup != string.Empty)
            {
                loadimage();
                
            }
        }
    }

    private void loadimage()
    {
        string id = Request.QueryString["id"];
        string idGroup = Request.QueryString["idgroup"];

        frmViewDetail.DataSource = itemDAO.GetvItemByID(Global.ConvertToInt(id), Global.ConvertToInt(idGroup));
        frmViewDetail.DataBind();
    }
    protected void cmdMua_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            Label lblInfoAddCart1 = (Label)frmViewDetail.FindControl("lblInfoAddCart");
            lblInfoAddCart1.Text = "";

            string id = Request.QueryString["id"];
            BasePage.SetShoppingCartSesstion(id + "|0");

            List<TblBookingDetail> arrItems = new List<TblBookingDetail>();
            if (Session[Global.SESSION_CART] != null)
                arrItems = (List<TblBookingDetail>)Session[Global.SESSION_CART];

            int iNoOfItems = 0;
            double dTotalAmount = 0;

            foreach (TblBookingDetail order in arrItems)
            {
                iNoOfItems += order.Quantity;
                dTotalAmount += Convert.ToDouble(order.Quantity) * Convert.ToDouble(order.Price);
            }
            lblInfoAddCart1.Text = "Đã thêm vào giỏ hàng ! ";

            ScriptManager.RegisterStartupScript(frmViewDetail,
             this.frmViewDetail.GetType(), "ScriptUpdateParents", "UpdateParentsCart('" + iNoOfItems.ToString() + "|" + dTotalAmount.ToString("0,00.##") + "');", true);
        }
        catch (Exception ex)
        {
            Session[Global.SESSION_ERROR] = ex;
            Response.Redirect(Global.ERROR_PAGE, true);
        }
    }
    protected void btnvote_Click(object sender, ImageClickEventArgs e)
    {

    }
}
